package com.kelvin.paopao.module.main.date.mydate;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.kelvin.paopao.R;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.main.date.mydate.myask.MyAskDateFragment;
import com.kelvin.paopao.module.main.date.mydate.mypublish.MyPublishDateFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/5/11.
 */

public class MyDateActivity extends BaseActivity {

    @BindView(R.id.stl)
    SlidingTabLayout stl;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private boolean isMyAsk;

    private final String[] mTitles = {
            "发布邀约", "报名邀约"
    };


    private MyAskDateFragment myAskDateFragment;
    private MyPublishDateFragment myPublishDateFragment;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_my_date;
    }

    @Override
    protected void initInjector() {
    }

    @Override
    protected void initViews() {
        isMyAsk = getIntent().getBooleanExtra("isMyAsk", false);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        myPublishDateFragment = MyPublishDateFragment.newInstance();
        myAskDateFragment = MyAskDateFragment.newInstance();


        ArrayList<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(myPublishDateFragment);
        fragmentList.add(myAskDateFragment);
        stl.setViewPager(viewPager, mTitles, this, fragmentList);

        if (isMyAsk) {
            viewPager.setCurrentItem(1);
        }
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    public static void launch(Context context) {
        Intent intent = new Intent(context, MyDateActivity.class);
        context.startActivity(intent);
    }

    public static void launch(Context context, boolean isMyAsk) {
        Intent intent = new Intent(context, MyDateActivity.class);
        intent.putExtra("isMyAsk", isMyAsk);
        context.startActivity(intent);
    }
}
